package org.dtrd.modules.content.articles.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.content.articles.entity.bean.CheckCategory;
import org.dtrd.modules.content.articles.entity.po.DtrdExtEmsYwCheckListCategory;
import org.dtrd.modules.content.articles.mapper.DtrdExtEmsYwCheckListCategoryMapper;
import org.dtrd.modules.content.articles.service.IDtrdExtEmsYwCheckListCategoryService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
@author 萧
@date 2021-08-25 17:37:46
**/
@Service
@DS("multi-datasource1")
public class DtrdExtEmsYwCheckListCategoryServiceImpl extends ServiceImpl<DtrdExtEmsYwCheckListCategoryMapper, DtrdExtEmsYwCheckListCategory> implements IDtrdExtEmsYwCheckListCategoryService {
    @Override
    public List<CheckCategory> selectCategories() {
        LambdaQueryWrapper<DtrdExtEmsYwCheckListCategory> query = Wrappers.lambdaQuery(DtrdExtEmsYwCheckListCategory.class)
                .eq(DtrdExtEmsYwCheckListCategory::getIsDel,0)
                .orderByDesc(DtrdExtEmsYwCheckListCategory::getDataId);
        List<DtrdExtEmsYwCheckListCategory> list = baseMapper.selectList(query);
        if (list != null) {
            List<CheckCategory> dataList = new ArrayList<>(list.size());
            list.stream().map(po -> new CheckCategory().parseFromPO(po)).forEach(dataList::add);
            return dataList;
        }
        return null;
    }
}
